<template>
    <el-dialog
            :title="!dataForm.followUpId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="跟进记录ID，主键" prop="followUpId">
                        <el-input v-model.number="dataForm.followUpId" placeholder="跟进记录ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="关联的客户ID" prop="customerId">
                        <el-input v-model.number="dataForm.customerId" placeholder="关联的客户ID"></el-input>
                </el-form-item>
                <el-form-item label="跟进类型" prop="followUpType">
                        <el-input v-model="dataForm.followUpType" placeholder="跟进类型"></el-input>
                </el-form-item>
                <el-form-item label="跟进时间" prop="followUpTime">
                        <el-date-picker
                                v-model="dataForm.followUpTime"
                                type="datetime"
                                placeholder="跟进时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="跟进人" prop="followUpBy">
                        <el-input v-model="dataForm.followUpBy" placeholder="跟进人"></el-input>
                </el-form-item>
                <el-form-item label="跟进内容" prop="followUpContent">
                        <el-input v-model="dataForm.followUpContent" placeholder="跟进内容"></el-input>
                </el-form-item>
                <el-form-item label="跟进结果" prop="followUpResult">
                        <el-input v-model="dataForm.followUpResult" placeholder="跟进结果"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            followUpId: null,
            customerId: null,
            followUpType: null,
            followUpTime: null,
            followUpBy: null,
            followUpContent: null,
            followUpResult: null
          },
          dataRule: {
            followUpId: [
                        { required: true, message: '跟进记录ID，主键不能为空', trigger: 'blur' }
            ],
            customerId: [
                        { required: true, message: '关联的客户ID不能为空', trigger: 'blur' }
            ],
            followUpType: [
                        { required: true, message: '跟进类型不能为空', trigger: 'blur' }
            ],
            followUpTime: [
                        { required: true, message: '跟进时间不能为空', trigger: 'blur' }
            ],
            followUpBy: [
                        { required: true, message: '跟进人不能为空', trigger: 'blur' }
            ],
            followUpContent: [
                        { required: true, message: '跟进内容不能为空', trigger: 'blur' }
            ],
            followUpResult: [
                        { required: true, message: '跟进结果不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.followUpId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.followUpId = id || 0
            if (this.dataForm.followUpId) {
              this.$http({
                url: this.$http.adornUrl(`/app/customer_follow_up/info/${this.dataForm.followUpId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appcustomerfollowup
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/customer_follow_up/${!this.dataForm.followUpId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>